﻿<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#-- Freemark的包含指令 -->
    <#include "../common/header.ftl"/>
    <script src="/js/My97DatePicker/WdatePicker.js"></script>
<script>
   $(function () {
       //给模态框的时间输入框绑定日历插件
       $("#inputModal input[name='schedule']").click(function () {
           WdatePicker({
               readOnly:true,
               minDate:new Date()
           });
       });
       //给修改按钮绑定点击事件
        $(".showContentBtn").click(function () {
            //进行回显
            var json = $(this).data("json");
            //将当前游记的id存入容器中
            var travelId = json.travelId;
            $("#editForm input[name='id']").val(json.id);
            $("#editForm input[name='title']").val(json.title);
            $("#editForm input[name='subTitle']").val(json.subTitle);
            $("#editForm img[id='coverUrl']").prop("src",json.coverUrl);
            $("#editForm input[name='coverUrl']").val(json.coverUrl);
            $("#editForm input[name='schedule']").val(json.schedule);
            $("#editForm select[name='type']").val(json.type);
            //给a标签设置src
            $(".showTravel").attr("href","/travel/releaseList.do?id="+travelId);
            //触发模态框
            $("#inputModal").modal('show');
        });
        //给模态框保存按钮绑定点击事件,提交表单
       $(".modalBtn").click(function () {
           //发送ajax请求,提交表单
           //将表单的提交方式修改为ajax异步提交
           $("#editForm").ajaxSubmit(function (data) {
               if(data.success){
                   $.messager.alert("温馨提示","操作成功,1.5S之后关闭");
                   setTimeout(function () {
                       window.location.reload();
                   },1500);
               }
           })
       });
   })
</script>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#--欢迎-->
    <#include "../common/top.ftl"/>

    <div class="row">
        <div class="col-sm-3">
            <#-- Freemark设置共享变量的指令 -->
            <#assign menu="travelCommend"/>
            <#--左侧菜单-->
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">游记推荐管理</h1>
                </div>
            </div>
            <#-- 高级查询 -->
            <form class="form-inline" id="searchForm" action="/travelCommend/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <select class="form-control" id="typeSelect" name="type">
                        <option value="0">全部</option>
                        <option value="1">每周推荐</option>
                        <option value="2">每月推荐</option>
                        <option value="3">攻略推荐</option>
                    </select>
                </div>
                <input type="submit" id="btn_query" class="btn btn-default" value="查询">

            </form>
            <#--回显下拉框-->
            <script>
                $("#typeSelect").val(${qo.type});
            </script>
            <table class="table table-striped table-hover" >
                <thead>
                <tr>
                    <th>编号</th>
                    <th>封面</th>
                    <th>标题</th>
                    <th>副标题</th>
                    <th>推荐时间安排</th>
                    <th>推荐类型</th>
                    <th></th>
                </tr>
                </thead>
            <#-- Freemark指令做循环迭代 -->
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index + 1}</td>
                        <td><img src="${(entity.coverUrl)!}" width="30px"/></td>
                        <td>${(entity.title)!}</td>
                        <td>${(entity.subTitle)!}</td>
                        <td>${(entity.schedule)!?string('yyyy-MM-dd')}</td>
                        <td>${(entity.typeName)!}</td>
                        <td>
                            <a class="btn btn-info btn-xs btn-input showContentBtn" data-json='${(entity.json)!}'>
                                <span class="glyphicon glyphicon-pencil" ></span>修改
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>

            <#--分页-->
            <#include "../common/page.ftl" />
        </div>
    </div>
</div>
<#--推荐游记的模态框-->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">新增游记推荐</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/travelCommend/saveOrUpdate.do" method="post" id="editForm" enctype="multipart/form-data">
                    <input type="hidden" name="id" >
                    <div class="form-group">
                        <label for="name" class="col-sm-4 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="title" name="title" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="name" class="col-sm-4 control-label">副标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="subTitle" name="subTitle" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sn" class="col-sm-4 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img id="coverUrl" width="100%"/>
                            <input type="file" class="form-control" name="file" >
                            <input type="hidden" class="form-control" name="coverUrl" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sn" class="col-sm-4 control-label">推荐时间：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="schedule" name="schedule" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sn" class="col-sm-4 control-label">推荐类型：</label>
                        <div class="col-sm-6">
                            <select id="auditState" class="form-control" autocomplete="off" name="type" >
                                <option value="1">每周推荐</option>
                                <option value="2">每月推荐</option>
                                <option value="3">攻略推荐</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" style="text-align: center">
                        <a class="showTravel" target="_blank">点击查看游记文章明细</a>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary btn-submit modalBtn">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</body>
</html>